package cn.itcast.bos.Dao;

import cn.itcast.crm.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.ws.rs.QueryParam;
import java.util.List;

/**
 * Created by Administrator on 2017/7/24.
 */
public interface CustomerRepository extends JpaRepository<Customer,Integer> {

    List<Customer> findByFixedAreaIdIsNull();

    List<Customer> findByFixedAreaId(String fixedAreaId);
    @Query("update Customer set fixedAreaId=null where fixedAreaId=?")
    @Modifying
    void clearFixedAreaId(String fixedAreaId);
    @Query("update Customer set fixedAreaId=? where id=?")
    @Modifying
    void updateFixedareaById(String fixedAreaId, Integer id);
    //通过电话号码查找
    Customer findByTelephone(String telephone);
        //修改状态
    @Query("update Customer set type=1 where telephone=?")
    @Modifying
    void UpdateTypeByTelephone(String telephone);
    //登陆的方法
    Customer findByUsernameAndPassword(String username, String password);
    //根据地址查询分区Id的方法
    @Query("select fixedAreaId from Customer where address=?")
    String findByFixedAreaIdByAddress(String address);
}
